#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>

bool is_prime(int x) {
    if (x % 2 == 0) {
        return x == 2;
    }
    int p = 3;
    while (p * p <= x && x % p != 0) {
        p += 2;
    }
    return p * p > x;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> b;
    std::string temp;
    for (char c : input) {
        if (c == ' ') {
            b.push_back(temp);
            temp.clear();
        } else {
            temp += c;
        }
    }
    b.push_back(temp);

    std::string number = "";

    for (const std::string& i : b) {
        if (i == "zero") {
            number += '0';
        } else if (i == "one") {
            number += '1';
        } else if (i == "two") {
            number += '2';
        } else if (i == "three") {
            number += '3';
        } else if (i == "four") {
            number += '4';
        } else if (i == "five") {
            number += '5';
        } else if (i == "six") {
            number += '6';
        } else if (i == "seven") {
            number += '7';
        } else if (i == "eight") {
            number += '8';
        } else if (i == "nine") {
            number += '9';
        }
    }

    int numb = std::stoi(number);

    if (numb > 99 && numb < 1000) {
        int f = std::abs(numb - 2);
        int r = 2;
        int k = 3;
        while (true) {
            if (is_prime(k)) {
                int t = std::abs(numb - k);
                if (t < f) {
                    f = t;
                    r = k;
                } else {
                    std::cout << r << std::endl;
                    break;
                }
            }
            k += 2;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}